package com.food.eat.config;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import lombok.Builder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



/**
 * @Author RenPu
 * @Date 2023/9/18 15:33
 * @Version 1.0
 * @Description: 德鲁伊连接池，资源监控配置类得编写
 **/

@Configuration
public class DruidConf {


    //德鲁伊监控访问地址：http://localhost:8001/druid/login.html
    //                账户：root
    //                密码：root


    //1 德鲁伊可视化变盘bean的注册

    @Bean
    public ServletRegistrationBean druidDashboard(){

        ServletRegistrationBean dashboard
                = new ServletRegistrationBean(new StatViewServlet(),"/druid/*");
        dashboard.addInitParameter("loginUsername","root");
        dashboard.addInitParameter("loginPassword","root");
        return dashboard;

    }



    //2:设置访问资源的限制
    @Bean
    public FilterRegistrationBean statFilter(){

        FilterRegistrationBean filter = new FilterRegistrationBean(new WebStatFilter());
        //设置拦截规则
        filter.addUrlPatterns("/*");

        //设置暴露访问的资源
        filter.addInitParameter("exclusions","/druid/*");

       return filter;
    }




}
